package com.zy.web.controller.bs;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.zy.entity.bs.Cooperation;
import com.zy.pojo.query.bs.CooperationQuery;
import com.zy.pojo.vos.common.PageVo;
import com.zy.pojo.vos.common.ResultVo;
import com.zy.service.bs.CooperationService;
import com.zy.web.controller.base.BaseController;
import com.zy.web.utils.ResultUtil;

@RequestMapping({"bs/cooperation","m/bs/cooperation"})
@Controller
public class CooperationController extends BaseController {

	@Autowired
	private CooperationService cooperationService;

	/**
	 * 分页
 	 * 
 	 * @param cooperationQuery
	 * @param start
	 * @param limit
	 * @return
	 */
	@RequestMapping(value = {"pageCooperation","front/pageCooperation"})
	@ResponseBody
	public PageVo pageCooperation(CooperationQuery cooperationQuery, Integer start, Integer limit) {
		return this.cooperationService.pageCooperation(cooperationQuery, start, limit);
	}

	/**
	 * 新增
	 * 
	 * @param cooperation
	 * @return
	 */
	@RequestMapping(value = "saveCooperation", method = RequestMethod.POST)
	@ResponseBody
	public ResultVo saveCooperation(List<MultipartFile> cooperationImgs,Cooperation cooperation) {
		try {
			cooperation.setCreateUserId(super.getCurrentUser().getId());
			this.cooperationService.saveCooperation(cooperation,cooperationImgs);
			return ResultUtil.success();
		} catch (Exception e) {
			return ResultUtil.error(log, e);
		}
	}
	
	/**
	 * 更新
	 * 
	 * @param cooperation
	 * @return
	 */
	@RequestMapping(value = "updateCooperation", method = RequestMethod.POST)
	@ResponseBody
	public ResultVo updateCooperation(Cooperation cooperation,List<MultipartFile> cooperationImgs) {
		try {
			cooperation.setModifyUserId(super.getCurrentUser().getId());
			this.cooperationService.updateCooperation(cooperation,cooperationImgs);
			return ResultUtil.success();
		} catch (Exception e) {
			return ResultUtil.error(log, e);
		}
	}

	/**
	 * 删除
	 * 
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "removeCooperation", method = RequestMethod.POST)
	@ResponseBody
	public ResultVo removeCooperation(long id) {
		try {
			this.cooperationService.removeCooperation(id);
			return ResultUtil.success();
		} catch (Exception e) {
			return ResultUtil.error(log, e);
		}
	}

	/**
	 * 恢复
	 * 
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "recover", method = RequestMethod.POST)
	@ResponseBody
	public ResultVo recover(long id) {
		try {
			this.cooperationService.recover(id);
			return ResultUtil.success();
		} catch (Exception e) {
			return ResultUtil.error(log, e);
		}
	}

}